<?php
class SleekBase_BaseModule extends Module {
	public function run () {
		# Meta data
		$this->setData('meta_author', conf('general.site_author'));
		$this->setData('meta_robots', 'all');
		$this->setData('meta_copyright', 'Copyright (c) ' . date('Y') . ' ' . conf('general.site_author'));
		$this->setData('meta_description', '');
		$this->setData('meta_keywords', '');

		# Cannonical URL?
		if (!empty($_SERVER['QUERY_STRING'])) {
			$this->setData('canonical_url', currPageURL(false));
		}
		else {
			$this->setData('canonical_url', false);
		}

		# Set view data (css, js_head and js_foot are set by SleekPHP)
		$requestedPage = SleekPHP::currentPage();

		$this->setData('html_id', strtolower(ccFix($requestedPage, '-')) . '-page');
		$this->setData('html_classes', $this->getHTMLClasses());
		$this->setData('html_title', (($requestedPage == HOME_PAGE and conf('general.site_tagline')) ? conf('general.site_tagline') : t(ccFix($requestedPage, ' '))) . ' - ' . conf('general.site_title'));
		$this->setData('ie_support', $this->getIESupportData());
		$this->setData('mobile_style_support', conf('general.mobile_style_support'));
	}

	private function getHTMLClasses () {
		$classes	= array();
		$classes[]	= 'lang-' . SleekPHP::currentLang();
		$classes[]	= 'user-auth-level-' . User()->authLevel();
		$classes[]	= DEBUG ? 'debug' : 'not-debug';

		return $classes;
	}

	private function getIESupportData () {
		$styleSupport	= conf('ie_support.style_support');
		$scriptSupport	= conf('ie_support.script_support');
		$ieSupportData	= array('support' => $styleSupport, 'fallback_style' => conf('ie_support.fallback_style'));

		# No style support
		if (!$styleSupport) {
			$ieSupportData['condition_open']			= '<!--[if !IE]><!-->';
			$ieSupportData['condition_close']			= '<!--<![endif]-->';
			$ieSupportData['fallback_condition_open']	= '<!--[if IE]>';
			$ieSupportData['fallback_condition_close']	= '<![endif]-->';
		}
		# Some style support
		elseif ($styleSupport !== true) {
			$ieSupportData['condition_open']			= "<!--[if gte IE $styleSupport]><!-->";
			$ieSupportData['condition_close']			= '<!--<![endif]-->';
			$ieSupportData['fallback_condition_open']	= "<!--[if lt IE $styleSupport]>";
			$ieSupportData['fallback_condition_close']	= '<![endif]-->';
		}

		# No script support
		if (!$scriptSupport) {
			$ieSupportData['js_condition_open']		= '<!--[if !IE]><!-->';
			$ieSupportData['js_condition_close']	= '<!--<![endif]-->';
		}
		# Some script support
		elseif ($scriptSupport !== true) {
			$ieSupportData['js_condition_open']		= "<!--[if gte IE $scriptSupport]><!-->";
			$ieSupportData['js_condition_close']	= '<!--<![endif]-->';
		}

		return $ieSupportData;
	}
}
